package com.dq.Week3.day14.homework;

import com.dq.Week3.day13.ddz.PukeCard;
import com.dq.Week3.day13.ddz.PukeCardUtils;

import java.util.*;

public class Again {
    public static void main(String[] args) {
        for (int i=0;i<5;i++) {
            // 生成一副扑克牌
            List<PukeCard> pukeList = PukeCardUtils.createPukeList();
//            System.out.println(pukeList);
            // 给三个玩家发牌
            PukeCardUtils pukeCardUtils = new PukeCardUtils();
            pukeCardUtils.drawCards(pukeList);

            ArrayList<PukeCard> p1List = pukeCardUtils.getP1();
            ArrayList<PukeCard> p2List = pukeCardUtils.getP2();
            ArrayList<PukeCard> p3List = pukeCardUtils.getP3();
            ArrayList<PukeCard> d1List = pukeCardUtils.getD1();
            p1List.sort((a,b)->a.getValue()-b.getValue());
            p2List.sort((a,b)->a.getValue()-b.getValue());
            p3List.sort((a,b)->a.getValue()-b.getValue());
            System.out.println(p1List);
            System.out.println(p2List);
            System.out.println(p3List);
            System.out.println(d1List);

            //计算一下每个玩家手中的炸弹数量
            int p1Boom =  boomNum("p1",p1List);
            System.out.println("p1的炸弹数量为"+p1Boom);
            int p2Boom =  boomNum("p2",p2List);
            System.out.println("p2的炸弹数量为"+p2Boom);
            int p3Boom =  boomNum("p3",p3List);
            System.out.println("p3的炸弹数量为"+p3Boom);

            System.out.println("==============================================");
        }


    }


    private static int boomNum(String player ,ArrayList<PukeCard> p1List) {
        HashMap<String, Integer> map = new HashMap<>();
        for (PukeCard pukeCard : p1List) {
            String point = pukeCard.getPoint();
            Integer oldValue = map.get(point);
            map.put(point, oldValue == null ? 1 : oldValue + 1);
        }

        Set<Map.Entry<String, Integer>> entries = map.entrySet();
        int boomCount = 0;
        for (Map.Entry<String, Integer> entry : entries) {
            if (entry.getValue()==4) {
                System.out.println(player+"的炸弹分布情况："+entry.getKey());
                boomCount++;
            }
        }
        // 统计王炸
        if (map.containsKey("SJOKER") && map.containsKey("BJOKER")) {
            System.out.println("王炸");
            boomCount++;
        }


        return boomCount;
    }
}
